﻿/// Name - MyHealth/ProcessRegistration.cs
/// Description - Accepts registration, sends email, forwards to confirm screen
/// Programmer - Dan Yatzeck
/// Date coded - 10/26/2011
/// Arguments - None
/// Variables -
///     _presenter - Object linking to parent Presenter
/// Files accessed by this code artifact - None
/// Files changed by this code artifact - None
/// I/O -
///     Input - Context.Items content with current user object
///     Output - Web page, session variable with current User object, sent registration email
/// Error Handling - None
/// Modifications -
///     1.0 - Initial coding
/// Known Faults -
///     1.0 - None known

using System;
using Microsoft.Practices.ObjectBuilder;
using Common;

namespace CSC440TeamOne.MyHealth.Views
{
    /// <summary>
    /// Process registration page
    /// </summary>
	public partial class ProcessRegistration : Microsoft.Practices.CompositeWeb.Web.UI.Page, IProcessRegistrationView
	{
		private ProcessRegistrationPresenter _presenter;

        /// <summary>
        /// Page Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				this._presenter.OnViewInitialized();
			}
			this._presenter.OnViewLoaded();

            // Get user object from previous page
            User user = Context.Items["userinfo"] as User;
            if (user == null)
            {
                Response.Redirect("Default.aspx", true);
            }

            // Save user object to the session
            Session["currentUser"] = user;

            // Encrypt the registration code
            string enc = Common.Cryptography.EncryptString(user.EmailAddress, "CSC440TeamOne");

            // Send it
            Common.Messaging.SendRegistrationEmail(user.EmailAddress, enc);

            // Redirect to confirmation page
            Server.Transfer("ConfirmRegistration.aspx?emailAddress=" + user.EmailAddress);
		}

        /// <summary>
        /// When this object is instantiated, create the presenter link
        /// </summary>
		[CreateNew]
		public ProcessRegistrationPresenter Presenter
		{
			get
			{
				return this._presenter;
			}
			set
			{
				if(value == null)
					throw new ArgumentNullException("value");

				this._presenter = value;
				this._presenter.View = this;
			}
		}

		// TODO: Forward events to the presenter and show state to the user.
		// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
		//	


        #region IProcessRegistrationView Members

        /// <summary>
        /// Show method, used for displaying content provided by underlying model
        /// </summary>
        /// <param name="model"></param>
        public void Show(ProcessRegistrationModel model)
        {
            
        }

        #endregion
    }
}

